﻿
using System;
using System.Collections.Generic;
using System.Data;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Threading;
using DevExpress.XtraReports.UI;
using prjKQXS_DLL;

namespace prjKQXS_UI.Lo_to
{
    public partial class frmInDoanhThu234SovaCapso : DevExpress.XtraEditors.XtraForm
    {
        public frmInDoanhThu234SovaCapso()
        {
            InitializeComponent();
        }

        private void btnThemmoi_Click(object sender, EventArgs e)
        {
            marqueeProgressBarControl1.Properties.Stopped = false;
            so = 0;
            capso = 2;
            Thread t = new Thread(new ThreadStart(inbaocao));
            t.SetApartmentState(ApartmentState.STA);
            t.Start();
        }

        private int so = 0;
        private int capso = 0;
        DateTime ngaythang = DateTime.Now;
        private void inbaocao()
        {            
            string madonvi = "";
            madonvi = lueDonVi.GetColumnValue("Ma_DT").ToString();
            ngaythang = deNgaythang.DateTime;
            prjKQXS_Report.rptTongHopDTTLotoCap4 rpt = new prjKQXS_Report.rptTongHopDTTLotoCap4(madonvi, so, capso, ngaythang);
            rpt.ShowRibbonPreviewDialog();
            marqueeProgressBarControl1.Properties.Stopped = true;
        }

        private void frmDoanhThuLoTo_Load(object sender, EventArgs e)
        {
            Control.CheckForIllegalCrossThreadCalls = false;
            marqueeProgressBarControl1.Properties.Stopped = true;
            deNgaythang.DateTime = DateTime.Now;
            loadDonVi();
        }

        private void loadDonVi()
        {
            try
            {
                SqlConnection conn = new SqlConnection(BienTc.connString);
                if (conn.State == ConnectionState.Closed)
                {
                    conn.Open();
                }

                SqlDataAdapter da = new SqlDataAdapter("Select * from DMDonVi where isPublic=1", conn);
                DataTable dt = new DataTable();
                da.Fill(dt);
                lueDonVi.Properties.DataSource = dt;
                if (dt.Rows.Count > 0)
                {
                    lueDonVi.ItemIndex = 0;
                }
            }
            catch
            {                                
            }
        }

        private void simpleButton6_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnXoa_Click(object sender, EventArgs e)
        {
            so = 0;
            capso = 3;
            marqueeProgressBarControl1.Properties.Stopped = false;
            Thread t = new Thread(new ThreadStart(inbaocao));
            t.SetApartmentState(ApartmentState.STA);
            t.Start();
        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            so = 0;
            capso = 4;
            marqueeProgressBarControl1.Properties.Stopped = false;         
            Thread t = new Thread(new ThreadStart(inbaocao));
            t.SetApartmentState(ApartmentState.STA);
            t.Start();
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            so = 2;
            capso = 0;
            marqueeProgressBarControl1.Properties.Stopped = false;         
            Thread t = new Thread(new ThreadStart(inbaocao));
            t.SetApartmentState(ApartmentState.STA);
            t.Start();
        }

        private void simpleButton2_Click(object sender, EventArgs e)
        {
            so = 3;
            capso = 0;
            marqueeProgressBarControl1.Properties.Stopped = false;         
            Thread t = new Thread(new ThreadStart(inbaocao));
            t.SetApartmentState(ApartmentState.STA);
            t.Start();
        }

        private void simpleButton4_Click(object sender, EventArgs e)
        {
            so = 4;
            capso = 0;
            marqueeProgressBarControl1.Properties.Stopped = false;         
            Thread t = new Thread(new ThreadStart(inbaocao));
            t.SetApartmentState(ApartmentState.STA);
            t.Start();
        }
    }
}